import { RouteRecordRaw } from 'vue-router';

/**
 * 建议：路由 path 路径与文件夹名称相同，找文件可浏览器地址找，方便定位文件位置
 *
 * 路由meta对象参数说明
 * meta: {
 *      title:          菜单栏及 tagsView 栏、菜单搜索名称（国际化）
 *      isLink：        是否超链接菜单，开启外链条件，`1、isLink: 链接地址不为空 2、isIframe:false`
 *      isHide：        是否隐藏此路由
 *      isKeepAlive：   是否缓存组件状态
 *      isAffix：       是否固定在 tagsView 栏上
 *      roles：         当前路由权限标识，取角色管理。控制路由显示、隐藏。超级管理员：admin 普通角色：common
 *      icon：          菜单、tagsView 图标，阿里：加 `iconfont xxx`，fontawesome：加 `fa xxx`
 * }
 */

// 扩展 RouteMeta 接口
declare module 'vue-router' {
	interface RouteMeta {
		title?: string;
		isLink?: string;
		isHide?: boolean;
		isKeepAlive?: boolean;
		isAffix?: boolean;
		roles?: string[];
		icon?: string;
	}
}

/**
 * 定义动态路由
 * 前端添加路由，请在顶级节点的 `children 数组` 里添加
 * @description 各字段请查看 `/@/views/system/menu/component/addMenu.vue 下的 ruleForm`
 * @returns 返回路由菜单数据
 */
export const dynamicRoutes: Array<RouteRecordRaw> = [
	{
		path: '/',
		name: '/',
		component: () => import('/@/layout/index.vue'),
		redirect: '/home',
		children: [
			{
				path: '/reload',
				name: 'reload',
				component: () => import('/@/views/reload.vue'),
				meta: {
					title: '重新加载',
					isKeepAlive: false
				},
			},
			{
				path: '/home',
				name: 'home',
				component: () => import('/@/views/home/index.vue'),
				meta: {
					title: '邮箱首页',
					isKeepAlive: true,
				},
			}, {
				path: '/customer',
				name: 'customer',
				component: () => import('/@/views/customer/index.vue'),
				meta: {
					title: '客户',
					isKeepAlive: true,
				},
			}, {
				path: '/supplier',
				name: 'supplier',
				component: () => import('/@/views/supplier/index.vue'),
				meta: {
					title: '供应商',
					isKeepAlive: true,
				},
			}, {
				path: '/template',
				name: 'template',
				component: () => import('/@/views/template/index.vue'),
				meta: {
					title: '模版',
					isKeepAlive: true,
				},
			}, {
				path: '/offer',
				name: 'offer',
				component: () => import('/@/views/offer/index.vue'),
				meta: {
					title: '询价',
				},
			}, {
				path: '/PI',
				name: 'PI',
				// component: () => import('/@/views/pi/index.vue'),
				meta: {
					title: '询价',
				},
				redirect: '/PI/index',
				children: [
					{
						path: '/PI/index',
						name: 'PIIndex',
						component: () => import('/@/views/pi/index.vue'),
						meta: {
							title: '询价',
							isKeepAlive: true,
						},
					},
					{
						path: '/PI/create',
						name: 'PICreate',
						component: () => import('/@/views/pi/createPI.vue'),
						meta: {
							title: '询价',
							isKeepAlive: true,
						},
					},
					{
						path: '/PI/edit/:id',
						name: 'PIEdit',
						component: () => import('/@/views/pi/createPI.vue'),
						meta: {
							title: '询价',
						},
					}
				]
			}, {
				path: '/order',
				name: 'order',
				meta: {
					title: '订单',
				},
				redirect: '/order/index',
				children: [
					{
						path: '/order/index',
						name: 'orderIndex',
						component: () => import('/@/views/order/index.vue'),
						meta: {
							title: '订单列表',
							isKeepAlive: true,
						},
					},
					{
						path: '/order/create',
						name: 'orderCreate',
						component: () => import('/@/views/order/create.vue'),
						meta: {
							title: '下单',
							isKeepAlive: true,
						},
					},
					{
						path: '/order/edit/:id',
						name: 'orderEdit',
						component: () => import('/@/views/order/create.vue'),
						meta: {
							title: '修改订单',
						},
					}
				]
			},
			{
				path: '/chat',
				redirect: '/chat/index',
				name: 'Chat',
				meta: {
					title: '即时通信',
					icon: 'i-lucide:message-circle',
				},
				children: [
					{
					path: '/chat/index',
					name: 'ChatIndex',
					component: () => import('/@/views/chat/index.vue'),
					meta: {
						title: '聊天',
						icon: 'i-lucide:message-square',
						cache: true,
					},
					},
				],
			}, {
				path: '/voucher',
				name: 'voucher',
				meta: {
					title: '凭证管理',
				},
				redirect: '/voucher/index',
				children: [
					{
						path: '/voucher/index',
						name: 'voucherIndex',
						component: () => import('/@/views/voucher/index.vue'),
						meta: {
							title: '凭证列表',
							isKeepAlive: true,
						},
					},
				]
			}, {
				path: '/cardApply',
				name: 'cardApply',
				meta: {
					title: '刷卡申请',
				},
				redirect: '/cardApply/index',
				children: [
					{
						path: '/cardApply/index',
						name: 'cardApplyIndex',
						component: () => import('/@/views/cardApply/index.vue'),
						meta: {
							title: '申请列表',
							isKeepAlive: true,
						},
					},
				]
			}, {
				path: '/file',
				name: 'fileManage',
				meta: {
					title: '文件库',
				},
				redirect: '/file/index',
				children: [
					{
						path: '/file/index',
						name: 'fileManageIndex',
						component: () => import('/@/views/file/index.vue'),
						meta: {
							title: '文件管理',
							isKeepAlive: true,
						},
					},
				]
			}
		],
	},
];

/**
 * 定义404、401界面
 * @link 参考：https://next.router.vuejs.org/zh/guide/essentials/history-mode.html#netlify
 */
export const notFoundAndNoPower = [
	{
		path: '/:path(.*)*',
		name: 'notFound',
		component: () => import('/@/views/error/404.vue'),
		meta: {
			title: 'message.staticRoutes.notFound',
			isHide: true,
		},
	},
	{
		path: '/401',
		name: 'noPower',
		component: () => import('/@/views/error/401.vue'),
		meta: {
			title: 'message.staticRoutes.noPower',
			isHide: true,
		},
	},
];

/**
 * 定义静态路由（默认路由）
 * 此路由不要动，前端添加路由的话，请在 `dynamicRoutes 数组` 中添加
 * @description 前端控制直接改 dynamicRoutes 中的路由，后端控制不需要修改，请求接口路由数据时，会覆盖 dynamicRoutes 第一个顶级 children 的内容（全屏，不包含 layout 中的路由出口）
 * @returns 返回路由菜单数据
 */
export const staticRoutes: Array<RouteRecordRaw> = [
	{
		path: '/login',
		name: 'login',
		component: () => import('/@/views/login/index.vue'),
		meta: {
			title: '登录',
		},
	},
];
